/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: swx  Date: 2019/09/10 Time: 16:03
 *
 * 客房清洁
 */

import React, {Component} from 'react';
import {
    View,
    Text,
    TouchableOpacity,
    TouchableHighlight, ScrollView, SafeAreaView, Image, Platform, BackHandler, RefreshControl
} from 'react-native';
import {connect} from 'react-redux';
import {styles} from './roomCleanScreen.Style';
import {retrieveOrderSweep} from "./Actions";
import {FetchStatus} from "../../../configuration/RequestConfiguration";
import {ReturnStatus} from "../../../configuration/ReturnStatus";
import {doDisplayWarnMessage} from "../../../component/Message/Action";
import {COLOR_FOCUS, COLOR_THEME, COLOR_WHITE, FONT_COLOR_TITLE} from "../../../constant/PHColors";
import HS_TouchableHighlight from "../../../hsstyle/HS_TouchableHighlight";
import AntDesign from "react-native-vector-icons/AntDesign";
import Feather from "react-native-vector-icons/Feather";
import FontAwesome from "react-native-vector-icons/FontAwesome";
import LoadingView from "../../../component/LoadingView/LoadingView";
import ScrollableTabView, { DefaultTabBar,ScrollableTabBar } from 'react-native-scrollable-tab-view';
import {SCREEN_WIDTH} from "../../../constant/PHScreen";


class roomCleanScreen extends Component {

    static navigationOptions = ({navigation}) => ({
        headerTitle: `客房清洁`,
        headerRight: (
            <TouchableOpacity activeOpacity={0.9} onPress={
                // navigation.getParam('setModalVisible')
                ()=>{
                    // console.log(JSON.stringify(navigation.state.params.Myroom()));
                    navigation.navigate('SelectRoomScreen',{"room_dataSource":navigation.state.params.Roomsall(),"myroom":navigation.state.params.Myroom()})
                }

            }>
                <View style={{width: 80, height: 44, flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}}>
                    <AntDesign name={'plus'} size={25} style={{color: '#212121', marginLeft: 10,fontWeight: 'bold'}}/>
                </View>
            </TouchableOpacity>
        )
    });

    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            order_w_finished:[],//完成
            order_w_scurry:[],  //赶房
            order_w_clean:[],   //清洁
            order_i_ftp:[],         //检查
            order_i_finished:[],    //清洁完成
            order_i_checked:[],     //检查完成
            order_i_clean:[],       //清洁中
            floor_c:'',         //按照楼型楼层分类数组
            floor_c_check:'',   //检查任务按照楼型楼层分类数组
            roomNum:{},         //每个类型的客房数量
            order_w_arr:[],
            order_i_ftp_arr:[],
            ftpnoicoArr:[],
            roomsall:[],           //全部房间
            key:'',
            freshScreen:'',
            freshScreenRandom:this.props.navigation.getParam("freshScreen")?this.props.navigation.getParam("freshScreen"):"",
            isRefreshing:false,
        };

        this.floor_c = [];
    }

    // shouldComponentUpdate(nextProps, nextState): void  {
    //     // let {dispatch} = this.props;
    //     // let str = {};
    //     // dispatch(retrieveOrderSweep(JSON.stringify(str)))
    //
    //     console.log(JSON.stringify(nextProps))
    //     console.log(JSON.stringify(this.props))
    //
    //     // if(nextState.order_w_arr === this.state.order_w_arr && nextState.order_i_ftp_arr === this.state.order_i_ftp_arr ){
    //     //     return false
    //     // }
    //
    //     return !(this.props.navigation.getParam("freshScreen")===this.state.freshScreenRandom)
    // }

    componentWillReceiveProps(nextProps, nextContext): void {
        let {dispatch} = this.props;



        if (nextProps.onOrderSweep !== this.props.onOrderSweep && nextProps.onOrderSweep.fetchStatus === FetchStatus.Success) {
            if (nextProps.onOrderSweep.RETURN === ReturnStatus.Success) {

                let order_w_arr = nextProps.onOrderSweep.order_w_ftp;
                let order_i_ftp_arr = nextProps.onOrderSweep.order_i_ftp;
                let roomsall = nextProps.onOrderSweep.roomsall;

                let order_w_finished = [];
                let order_w_scurry = [];
                let order_w_clean = [];
                let roomNumJson = {};

                let myroom = [];        //选择布草时我清洁的房间
                let myroom_num = [];        //选择布草时我清洁的房间
                order_w_arr.map((item, index) => {
                    if(item['whsk_status']==="完成清洁"||item['whsk_status']==="完成检查"||item['whsk_status']==="无法检查"){
                        order_w_finished.push(item)
                    }else if(item['ordertype']==="赶房"){
                        order_w_scurry.push(item)
                    }else{
                        order_w_clean.push(item)
                    }

                    let json = {"floor_c":item.floor_c,"room":item.room,"gno":item['gno']?item['gno']:''};
                    if(myroom_num.indexOf(item.room) < 0){
                        myroom.push(json);
                        myroom_num.push(item.room);
                    }
                })
                order_w_clean.map((item, index)=>{
                    let floor_c = item.floor_c;
                    if(roomNumJson[floor_c]){
                        roomNumJson[floor_c] = roomNumJson[floor_c]+1
                    }else{
                        roomNumJson[floor_c] = 1
                    }
                })
                // console.log("order_w_clean--------------"+JSON.stringify(order_w_clean));
                // console.log("order_w_scurry--------------"+JSON.stringify(order_w_scurry))

                let order_i_finished = [];
                let order_i_checked = [];
                let order_i_clean = [];
                order_i_ftp_arr.map((item, index) => {

                    if(item['whsk_status']==="完成清洁"){
                        order_i_finished.push(item)
                    }else if(item['whsk_status']==="完成检查"||item['whsk_status']==="无法检查"){
                        order_i_checked.push(item)
                    }else{
                        order_i_clean.push(item)
                    }

                    let json = {"floor_c":item.floor_c,"room":item.room,"gno":item['gno']?item['gno']:''};
                    if(myroom_num.indexOf(item.room) < 0){
                        myroom.push(json);
                        myroom_num.push(item.room);
                    }
                })

                this.setState({
                    order_w_arr:order_w_arr,
                    order_w_scurry:order_w_scurry,
                    order_w_finished:order_w_finished,
                    order_w_clean:order_w_clean,
                    order_i_ftp_arr:order_i_ftp_arr,
                    order_i_finished:order_i_finished,
                    order_i_checked:order_i_checked,
                    order_i_clean:order_i_clean,
                    roomNum:roomNumJson,
                    roomsall:roomsall,
                    myroom:myroom,
                    freshScreen:this.state.freshScreenRandom,
                    isRefreshing: false,
                })

                this.props.navigation.setParams({Roomsall:this.retrieveRoomsall,Myroom:this.retrieveMyroom});
            } else {
                dispatch(doDisplayWarnMessage(nextProps.onOrderSweep.MSG))
            }
        }
    }

    // 组件渲染后调用
    componentDidMount() {
        let {dispatch} = this.props;
        let str = {};
        dispatch(retrieveOrderSweep(JSON.stringify(str)))
    }

    retrieveRoomsall=()=>{
        return this.state.roomsall
    }

    retrieveMyroom=()=>{
        return this.state.myroom
    }

    render() {
        let {dispatch,onOrderSweep} = this.props;
        if (onOrderSweep.fetchStatus === FetchStatus.Success ) {
            if(this.state.order_i_ftp_arr.length>0||this.state.order_w_arr.length>0){
                return (
                    <ScrollableTabView
                        tabBarUnderlineColor="#4DC5FF"
                        tabBarTextStyle={{
                            fontSize:18
                        }}
                        tabBarUnderlineStyle={{backgroundColor:'#4C70FF'}}
                        tabBarActiveTextColor="#4C70FF"
                        style={styles.container}
                        renderTabBar={() => <DefaultTabBar />}
                    >

                        {
                            (this.state.order_w_arr.length>0)
                            &&
                            (
                                <View tabLabel='清洁任务' style={styles.container}>
                                    <SafeAreaView style={styles.container}>
                                        <ScrollView
                                            refreshControl={
                                                <RefreshControl
                                                    refreshing={this.state.isRefreshing}
                                                    onRefresh={this._onRefresh}
                                                    // colors={['#ccc']}
                                                    // progressBackgroundColor='#459cff'
                                                />
                                            }
                                            style={styles.scrollView}>
                                            {/*<View style={styles.headerContainer}>
                                                <View style={styles.headerLeft}>
                                                    <Text style={styles.headerText}>
                                                        清洁进度
                                                    </Text>
                                                </View>
                                                <View style={styles.headerCenter}>
                                                    <View style={styles.progressBar}>
                                                        <View style={[styles.progressBarDone,{ flex:0.3}]}>

                                                        </View>
                                                    </View>
                                                </View>
                                                <View style={styles.headerRight}>
                                                    <Text style={styles.headerText}>
                                                        1/6(退2空4)
                                                    </Text>
                                                </View>
                                            </View>*/}




                                            {
                                                (this.state.order_w_scurry.length>0)
                                                &&
                                                (
                                                    <View style={styles.cellView}>
                                                        <View style={styles.cellViewTitle}>
                                                            <View style={styles.cellLeftView}>
                                                                <Text style={styles.headerLeftTextHard}>
                                                                    赶房
                                                                </Text>
                                                            </View>
                                                            <View style={styles.cellRightView}>
                                                                <Text style={styles.headerRightTextHard}>
                                                                    共{this.state.order_w_scurry.length}间
                                                                </Text>
                                                            </View>
                                                        </View>
                                                        <View style={styles.cellViewBody}>
                                                            {
                                                                (this.state.order_w_scurry.length>0)
                                                                &&
                                                                (
                                                                    this.state.order_w_scurry.map((item, index) => {
                                                                        return this._renderScurry(item, index)
                                                                    })
                                                                )
                                                            }
                                                        </View>
                                                    </View>
                                                )
                                            }

                                            {
                                                (this.state.order_w_clean.length>0)
                                                &&
                                                (
                                                    <View style={styles.cellView}>
                                                        <View style={styles.cellViewTitle}>
                                                            <View style={styles.cellLeftView}>
                                                                <Text style={styles.headerLeftTextHard}>
                                                                    待清洁
                                                                </Text>
                                                            </View>
                                                            <View style={styles.cellRightView}>
                                                                <Text style={styles.headerRightTextHard}>
                                                                    共{this.state.order_w_clean.length}间
                                                                </Text>
                                                            </View>
                                                        </View>
                                                        {
                                                            this.state.order_w_clean.map((item, index) => {

                                                                if(this.floor_c.indexOf(item.floor_c)<0){

                                                                    if(this.state.order_w_clean.length===index+1){
                                                                        this.floor_c = [];
                                                                    }else{
                                                                        this.floor_c.push(item.floor_c);
                                                                    }
                                                                    return this._renderClean(item, index,'清洁人')
                                                                }else if(this.state.order_w_clean.length===index+1){
                                                                    this.floor_c = [];
                                                                }

                                                            })
                                                        }
                                                    </View>
                                                )

                                            }

                                            {
                                                (this.state.order_w_finished.length>0)
                                                &&
                                                (
                                                    <View style={styles.cellView}>
                                                        <View style={styles.cellViewTitle}>
                                                            <View style={styles.cellLeftView}>
                                                                <Text style={styles.headerLeftTextHard}>
                                                                    已完成
                                                                </Text>
                                                            </View>
                                                            <View style={styles.cellRightView}>
                                                                <Text style={styles.headerRightTextHard}>
                                                                    共{this.state.order_w_finished.length}间
                                                                </Text>
                                                            </View>
                                                        </View>
                                                        <View style={styles.cellViewBody}>
                                                            {
                                                                (this.state.order_w_finished.length>0)
                                                                &&
                                                                (
                                                                    this.state.order_w_finished.map((item, index) => {
                                                                        return this._renderFinished(item, index)
                                                                    })
                                                                )
                                                            }
                                                        </View>
                                                    </View>
                                                )
                                            }
                                        </ScrollView>
                                    </SafeAreaView>
                                </View>
                            )
                        }

                        {
                            (this.state.order_i_ftp_arr.length>0)
                            &&
                            (
                                <View tabLabel='检查任务' style={styles.container}>
                                    <SafeAreaView style={styles.container}>
                                        <ScrollView
                                            refreshControl={
                                                <RefreshControl
                                                    refreshing={this.state.isRefreshing}
                                                    onRefresh={this._onRefresh}
                                                    // colors={['#ccc']}
                                                    // progressBackgroundColor='#459cff'
                                                />
                                            }
                                            style={styles.scrollView}>
                                            {/*<View style={styles.container}>
                                                <View style={styles.headerContainer}>
                                                    <View style={styles.headerLeft}>
                                                        <Text style={styles.headerText}>
                                                            检查进度
                                                        </Text>
                                                    </View>
                                                    <View style={styles.headerCenter}>
                                                        <View style={styles.progressBar}>
                                                            <View style={[styles.progressBarDone,{ flex:0.3}]}>

                                                            </View>
                                                        </View>
                                                    </View>
                                                    <View style={styles.headerRight}>
                                                        <Text style={styles.headerText}>
                                                            1/6(退2空4)
                                                        </Text>
                                                    </View>
                                                </View>
                                            </View>*/}


                                            {/*<View style={styles.roomDiskBox}>*/}

                                            {
                                                (this.state.order_i_finished.length>0)
                                                &&
                                                (
                                                    <View style={styles.cellView}>
                                                        <View style={styles.cellViewTitle}>
                                                            <View style={styles.cellLeftView}>
                                                                <Text style={styles.headerLeftTextHard}>
                                                                    待检查
                                                                </Text>
                                                            </View>
                                                            <View style={styles.cellRightView}>
                                                                <Text style={styles.headerRightTextHard}>
                                                                    共{this.state.order_i_finished.length}间
                                                                </Text>
                                                            </View>
                                                        </View>
                                                        <View style={styles.cellViewBody}>
                                                            {
                                                                (this.state.order_i_finished.length>0)
                                                                &&
                                                                (
                                                                    this.state.order_i_finished.map((item, index) => {
                                                                        return this._renderFinished_i(item, index)
                                                                    })
                                                                )
                                                            }
                                                        </View>
                                                    </View>
                                                )
                                            }

                                            <View style={styles.cellViewBody}>
                                                {
                                                    (this.state.order_i_clean.length>0)
                                                    &&
                                                    (
                                                        /*this.state.order_i_clean.map((item, index) => {
                                                            let menu = "false";
                                                            if(this.state.floor_c_check === item.floor_c){
                                                                menu="false"
                                                            }else{
                                                                menu="true"
                                                            }
                                                            this.state.floor_c_check = item.floor_c;
                                                            return (
                                                                this._renderRoomsView(item, index,menu)
                                                            );

                                                        })*/

                                                        (
                                                            <View style={styles.cellView}>
                                                                <View style={styles.cellViewTitle}>
                                                                    <View style={styles.cellLeftView}>
                                                                        <Text style={styles.headerLeftTextHard}>
                                                                            待清洁
                                                                        </Text>
                                                                    </View>
                                                                    <View style={styles.cellRightView}>
                                                                        <Text style={styles.headerRightTextHard}>
                                                                            共{this.state.order_i_clean.length}间
                                                                        </Text>
                                                                    </View>
                                                                </View>
                                                                {
                                                                    this.state.order_i_clean.map((item, index) => {

                                                                        if(this.floor_c.indexOf(item.floor_c)<0){

                                                                            if(this.state.order_i_clean.length===index+1){
                                                                                this.floor_c = [];
                                                                            }else{
                                                                                this.floor_c.push(item.floor_c);
                                                                            }
                                                                            return this._renderClean(item, index,'检查人')
                                                                        }else if(this.state.order_i_clean.length===index+1){
                                                                            this.floor_c = [];
                                                                        }

                                                                    })
                                                                }
                                                            </View>
                                                        )
                                                    )
                                                }
                                            </View>

                                            {
                                                (this.state.order_i_checked.length>0)
                                                &&
                                                (
                                                    <View style={styles.cellView}>
                                                        <View style={styles.cellViewTitle}>
                                                            <View style={styles.cellLeftView}>
                                                                <Text style={styles.headerLeftTextHard}>
                                                                    检查完成
                                                                </Text>
                                                            </View>
                                                            <View style={styles.cellRightView}>
                                                                <Text style={styles.headerRightTextHard}>
                                                                    共{this.state.order_i_checked.length}间
                                                                </Text>
                                                            </View>
                                                        </View>
                                                        <View style={styles.cellViewBody}>
                                                            {
                                                                (this.state.order_i_checked.length>0)
                                                                &&
                                                                (
                                                                    this.state.order_i_checked.map((item, index) => {
                                                                        return this._renderChecked_i(item, index)
                                                                    })
                                                                )
                                                            }
                                                        </View>
                                                    </View>
                                                )
                                            }
                                        </ScrollView>
                                    </SafeAreaView>
                                </View>
                            )
                        }
                    </ScrollableTabView>
                )

            }else{
                return (
                    <SafeAreaView style={styles.container}>
                        <View  style={styles.windowCenter}>
                            <Text style={styles.headerText}>
                                暂无任务
                            </Text>
                        </View>
                    </SafeAreaView>
                )
            }

        }else{
            return <LoadingView/>
        }

    }

    //刷新页面
    _onRefresh=()=>{
        let {dispatch} = this.props;

        this.setState({isRefreshing: true});

        let str = {};
        dispatch(retrieveOrderSweep(JSON.stringify(str)))
    }

    //循环已完成任务
    _renderFinished=(item, index)=>{
        let _this = this;
        return(
            <View key={index} style={[styles.roomBox,{borderColor:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                <HS_TouchableHighlight onPress={()=>{
                    this.props.navigation.navigate('RoomStatusScreen',{room:item.room,button:'yes',authority:'清洁人',orderid:item.orderid,callBack:()=>_this.freshScreen()});
                }}>
                    <View  style={styles.roomBoxTouch}>
                        <View style={styles.roomBoxLeft}>
                            <Text style={[styles.roomBoxLeftText,{color:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                                {this.whsk_status_show(item)}
                            </Text>
                        </View>
                        <View style={[styles.roomBoxRight,{backgroundColor:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                            {/*<Text style={[styles.roomBoxRightText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                {item['room']}
                            </Text>*/}
                            <View style={styles.cellRoomDiskView}>
                                <View style={styles.cellLeftViewRoomBox}>
                                    <View style={styles.cellLeftTopView}>
                                        <Text style={[styles.cellLeftTopText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                            {item.room}
                                            {
                                                (item.connecting!==""&&"undefined"!==typeof(item.connecting))&&(<FontAwesome name={'code-fork'} size={15} style={{color: 'blue'}}/>)
                                            }
                                        </Text>
                                    </View>
                                    <View style={styles.cellLeftMidView}>
                                        <Text style={[styles.cellLeftMidText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                            {item.rmtype_c}
                                        </Text>
                                    </View>
                                </View>
                                <View style={styles.cellRightViewRoomBox}>
                                    <View style={styles.cellRightIconView}>
                                        {_this.getIcon(item)}
                                    </View>
                                </View>
                            </View>
                            <View style={styles.cellRoomDiskView}>
                                <Text style={[{fontSize: 15,color:(item.syntcolor?item.syntcolor:'#fff'),flex:1, marginLeft: 5,}]}>
                                    {item.gname}
                                </Text>
                            </View>
                        </View>
                    </View>
                </HS_TouchableHighlight>
            </View>
        )
    }

    //循环检查人待检查
    _renderFinished_i=(item, index)=>{
        let _this = this;
        return(
            <HS_TouchableHighlight onPress={()=>{
                this.props.navigation.navigate('RoomStatusScreen',{room:item.room,button:'yes',authority:'检查人',orderid:item.orderid,callBack:()=>_this.freshScreen()});
            }}>
                <View  style={[styles.roomBoxTouch,{borderColor:(item.synbcolor?item.synbcolor:'#92d2ff'),borderWidth:1,marginLeft:SCREEN_WIDTH*0.04,marginTop:7,marginBottom:7,height:50}]}>
                    <View style={[{backgroundColor:'#fabd3a'},styles.roomBoxLeft]}>
                        <Text style={[styles.roomBoxLeftText,{color:'#000000'}]}>
                            {this.whsk_status_show(item)}
                        </Text>
                    </View>
                    <View style={[styles.roomBoxRight,{backgroundColor:(item.synbcolor?item.synbcolor:'#92d2ff'), flex:0.65,}]}>
                        <View style={styles.cellRoomDiskView}>
                            <View style={styles.cellLeftViewRoomBox}>
                                <View style={styles.cellLeftTopView}>
                                    <Text style={[styles.cellLeftTopText,{color:(item.syntcolor?item.syntcolor:'#000')}]}>
                                        {item.room}
                                        {
                                            (item.connecting!==""&&"undefined"!==typeof(item.connecting))&&(<FontAwesome name={'code-fork'} size={15} style={{color: 'blue'}}/>)
                                        }
                                    </Text>
                                </View>
                                <View style={styles.cellLeftMidView}>
                                    <Text style={[styles.cellLeftMidText,{color:(item.syntcolor?item.syntcolor:'#000')}]}>
                                        {item.rmtype_c}
                                    </Text>
                                </View>
                            </View>
                            <View style={styles.cellRightViewRoomBox}>
                                <View style={styles.cellRightIconView}>
                                    {_this.getIcon(item)}
                                </View>
                            </View>
                        </View>
                        <View style={styles.cellRoomDiskView}>
                            <Text style={[{fontSize: 15,color:(item.syntcolor?item.syntcolor:'#fff'),flex:1, marginLeft: 5,}]}>
                                {item.gname}
                            </Text>
                        </View>
                    </View>
                </View>
            </HS_TouchableHighlight>
        )
    }

    //循环检查完成
    _renderChecked_i=(item, index)=>{
        let _this = this;
        return(
            <HS_TouchableHighlight onPress={()=>{
                this.props.navigation.navigate('RoomStatusScreen',{room:item.room,button:'yes',authority:'检查人',orderid:item.orderid,callBack:()=>_this.freshScreen()});
            }}>
                <View  style={[styles.roomBoxTouch,{borderColor:(item.synbcolor?item.synbcolor:'#92d2ff'),borderWidth:1,marginLeft:SCREEN_WIDTH*0.04,marginTop:7,marginBottom:7,height:50}]}>
                    <View style={[styles.roomBoxLeft]}>
                        <Text style={[styles.roomBoxLeftText,{color:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                            {this.whsk_status_show(item)}
                        </Text>
                    </View>
                    <View style={[styles.roomBoxRight,{backgroundColor:(item.synbcolor?item.synbcolor:'#92d2ff'), flex:0.65,}]}>
                        <View style={styles.cellRoomDiskView}>
                            <View style={styles.cellLeftViewRoomBox}>
                                <View style={styles.cellLeftTopView}>
                                    <Text style={[styles.cellLeftTopText,{color:(item.syntcolor?item.syntcolor:'#000')}]}>
                                        {item.room}
                                        {
                                            (item.connecting!==""&&"undefined"!==typeof(item.connecting))&&(<FontAwesome name={'code-fork'} size={15} style={{color: 'blue'}}/>)
                                        }
                                    </Text>
                                </View>
                                <View style={styles.cellLeftMidView}>
                                    <Text style={[styles.cellLeftMidText,{color:(item.syntcolor?item.syntcolor:'#000')}]}>
                                        {item.rmtype_c}
                                    </Text>
                                </View>
                            </View>
                            <View style={styles.cellRightViewRoomBox}>
                                <View style={styles.cellRightIconView}>
                                    {_this.getIcon(item)}
                                </View>
                            </View>
                        </View>
                        <View style={styles.cellRoomDiskView}>
                            <Text style={[{fontSize: 15,color:(item.syntcolor?item.syntcolor:'#fff'),flex:1, marginLeft: 5,}]}>
                                {item.gname}
                            </Text>
                        </View>
                    </View>
                </View>
            </HS_TouchableHighlight>
        )
    }

    //循环赶房任务
    _renderScurry=(item, index)=>{
        let _this = this;
        let whsk_status = "";
        if(item['ordertype']==="赶房"){
            whsk_status = "赶房"
        }else{
            whsk_status = this.whsk_status_show(item)
        }
        return(
            <View key={index} style={[styles.roomBox,{borderColor:'#cc3f32'}]}>
                <HS_TouchableHighlight onPress={()=>{
                    this.props.navigation.navigate('RoomStatusScreen',{room:item.room,button:'yes',authority:'清洁人',orderid:item.orderid,callBack:()=>_this.freshScreen()});
                }}>
                    <View  style={styles.roomBoxTouch}>
                        <View style={styles.roomBoxLeft}>
                            <Text style={[styles.roomBoxLeftText,{color:'#cc3f32',borderColor:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                                {whsk_status}
                            </Text>
                        </View>
                        <View style={[styles.roomBoxRight,{borderColor:'#cc3f32',backgroundColor:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                            {/*<Text style={[styles.roomBoxRightText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                {item['room']}
                            </Text>*/}
                            <View style={styles.cellRoomDiskView}>
                                <View style={styles.cellLeftViewRoomBox}>
                                    <View style={styles.cellLeftTopView}>
                                        <Text style={[styles.cellLeftTopText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                            {item.room}
                                            {
                                                (item.connecting!==""&&"undefined"!==typeof(item.connecting))&&(<FontAwesome name={'code-fork'} size={15} style={{color: 'blue'}}/>)
                                            }
                                        </Text>
                                    </View>
                                    <View style={styles.cellLeftMidView}>
                                        <Text style={[styles.cellLeftMidText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                            {item.rmtype_c}
                                        </Text>
                                    </View>
                                </View>
                                <View style={styles.cellRightViewRoomBox}>
                                    <View style={styles.cellRightIconView}>
                                        {_this.getIcon(item)}
                                    </View>
                                </View>
                            </View>
                            <View style={styles.cellRoomDiskView}>
                                <Text style={[{fontSize: 15,color:(item.syntcolor?item.syntcolor:'#fff'),flex:1, marginLeft: 5,}]}>
                                    {item.gname}
                                </Text>
                            </View>
                        </View>
                    </View>
                </HS_TouchableHighlight>
            </View>
        )
    };

    whsk_status_show=(item)=>{
        if(item.icon&&item.icon!==''){
            let html = <AntDesign name={item.icon} size={20} style={{color: COLOR_FOCUS}}/>;
            return html
        }else if(item.status1&&item.status1!==""){
            return item.status1
        }else{
            return item.whsk_status
        }
    };

    //循环清洁任务
    _renderClean=(item, index, type)=>{
            let floor_c = item.floor_c;
            return(
                <View key={index} style={[styles.cellView]}>
                    <View style={[styles.cellViewTitle,{height:30}]}>
                        <View style={styles.cellLeftView}>
                            <Text style={styles.headerLeftText}>
                                {item.floor_c}
                            </Text>
                        </View>
                        <View style={styles.cellRightView}>
                            {/*<Text style={styles.headerRightText}>
                                还有客房{this.state.roomNum[item.floor_c]?this.state.roomNum[item.floor_c]:0}
                            </Text>*/}
                        </View>
                    </View>
                    <View style={styles.cellViewBody}>

                        {
                            (type==="清洁人" && this.state.order_w_clean.length>0)
                            &&
                            (
                                this.state.order_w_clean.map((item1, index1 ) => {
                                    if(item1.floor_c===floor_c) {
                                        return this._renderClean_room(item1, index1,type)
                                    }
                                })
                            )
                        }
                        {
                            (type==="检查人" && this.state.order_i_clean.length>0)
                            &&
                            (
                                this.state.order_i_clean.map((item1, index1 ) => {
                                    if(item1.floor_c===floor_c) {
                                        return this._renderClean_room(item1, index1,type)
                                    }
                                })
                            )
                        }
                    </View>
                </View>
            )
    };

    _renderClean_room=(item, index ,type)=>{
        let _this = this;
        console.log(JSON.stringify(item))
        return(
            <View key={index} style={[styles.roomBox,{borderColor:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                <HS_TouchableHighlight onPress={()=>{
                    this.props.navigation.navigate('RoomStatusScreen',{room:item.room,button:'yes',authority:type,orderid:item.orderid,callBack:()=>_this.freshScreen()});
                }}>
                    <View  style={styles.roomBoxTouch}>
                        <View style={[styles.roomBoxLeft]}>
                            <Text style={[styles.roomBoxLeftText,{color:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                                {this.whsk_status_show(item)}
                            </Text>
                        </View>
                        <View style={[styles.roomBoxRight,{backgroundColor:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                            {/*<Text style={[styles.roomBoxRightText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>*/}
                                {/*{item.room}*/}
                            {/*</Text>*/}
                                <View style={styles.cellRoomDiskView}>
                                    <View style={styles.cellLeftViewRoomBox}>
                                        <View style={styles.cellLeftTopView}>
                                            <Text style={[styles.cellLeftTopText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                                {item.room}
                                                {
                                                    (item.connecting!==""&&"undefined"!==typeof(item.connecting))&&(<FontAwesome name={'code-fork'} size={15} style={{color: 'blue'}}/>)
                                                }
                                            </Text>
                                        </View>
                                        <View style={styles.cellLeftMidView}>
                                            <Text style={[styles.cellLeftMidText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                                {item.rmtype_c}
                                            </Text>
                                        </View>
                                    </View>
                                    <View style={styles.cellRightViewRoomBox}>
                                        <View style={styles.cellRightIconView}>
                                            {_this.getIcon(item)}
                                        </View>
                                    </View>
                                </View>
                            <View style={styles.cellRoomDiskView}>
                                <Text style={[{fontSize: 15,color:(item.syntcolor?item.syntcolor:'#fff'),flex:1, marginLeft: 5,}]}>
                                    {item.gname}
                                </Text>
                            </View>
                        </View>
                    </View>
                </HS_TouchableHighlight>
            </View>
        )

    };

    //房态盘循环
    _renderRoomsView=(item, index,menu)=>{
        let _this = this;
        let returnHtml;
        let menuHtml = (
            <View style={styles.cellFloorView}>
                <Text style={styles.cellFloorText}>
                    {item.floor_c}
                </Text>
            </View>
        );
        let roomHtml = (<HS_TouchableHighlight key={index} onPress={() => {
            this.props.navigation.navigate('RoomStatusScreen',{room:item.room,button:'yes',authority:'检查人',orderid:item.orderid,callBack:()=>_this.freshScreen()});
        }}>
            {/*<View style={[styles.cellViewRoomBox,{backgroundColor:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                <View style={styles.cellRoomDiskView}>
                    <View style={styles.cellLeftViewRoomBox}>
                        <View style={styles.cellLeftTopView}>
                            <Text style={[styles.cellLeftTopText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                {item.room}
                                {
                                    (item.connecting!==""&&"undefined"!==typeof(item.connecting))&&(<FontAwesome name={'code-fork'} size={15} style={{color: 'blue'}}/>)
                                }
                            </Text>
                        </View>
                        <View style={styles.cellLeftMidView}>
                            <Text style={[styles.cellLeftMidText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>
                                {item.rmtype_c}
                            </Text>
                        </View>
                    </View>
                    <View style={styles.cellRightViewRoomBox}>
                        <View style={styles.cellRightIconView}>
                            {_this.getIcon(item)}
                        </View>
                    </View>
                    <View style={styles.cellBottomView}>
                        <Text style={[styles.cellRightBottomText,{color:item.syntcolor}]}>
                            {item.gname}
                        </Text>
                    </View>
                </View>
            </View>*/}
            <View  style={[styles.roomBoxTouch,{borderColor:(item.synbcolor?item.synbcolor:'#92d2ff'),borderWidth:1,marginLeft:SCREEN_WIDTH*0.04,marginTop:7,marginBottom:7,height:50}]}>
                <View style={[styles.roomBoxLeft]}>
                    <Text style={[styles.roomBoxLeftText,{color:(item.synbcolor?item.synbcolor:'#92d2ff')}]}>
                        {this.whsk_status_show(item)}
                    </Text>
                </View>
                <View style={[styles.roomBoxRight,{backgroundColor:(item.synbcolor?item.synbcolor:'#92d2ff'), flex:0.65,}]}>
                    {/*<Text style={[styles.roomBoxRightText,{color:(item.syntcolor?item.syntcolor:'#fff')}]}>*/}
                    {/*{item.room}*/}
                    {/*</Text>*/}
                    <View style={styles.cellRoomDiskView}>
                        <View style={styles.cellLeftViewRoomBox}>
                            <View style={styles.cellLeftTopView}>
                                <Text style={[styles.cellLeftTopText,{color:(item.syntcolor?item.syntcolor:'#000')}]}>
                                    {item.room}
                                    {
                                        (item.connecting!==""&&"undefined"!==typeof(item.connecting))&&(<FontAwesome name={'code-fork'} size={15} style={{color: 'blue'}}/>)
                                    }
                                </Text>
                            </View>
                            <View style={styles.cellLeftMidView}>
                                <Text style={[styles.cellLeftMidText,{color:(item.syntcolor?item.syntcolor:'#000')}]}>
                                    {item.rmtype_c}
                                </Text>
                            </View>
                        </View>
                        <View style={styles.cellRightViewRoomBox}>
                            <View style={styles.cellRightIconView}>
                                {_this.getIcon(item)}
                            </View>
                        </View>
                    </View>
                    <View style={styles.cellRoomDiskView}>
                        <Text style={[{fontSize: 15,color:(item.syntcolor?item.syntcolor:'#fff'),flex:1, marginLeft: 5,}]}>
                            {item.gname}
                        </Text>
                    </View>
                </View>
            </View>
        </HS_TouchableHighlight>);

        if(menu==="true"){
            returnHtml = [menuHtml,roomHtml]
        }else{
            returnHtml = roomHtml
        }

        return(
            returnHtml
        )
    };

    getIcon=(item)=>{
        // console.log(JSON.stringify(item))
        return (
            <View style={{flexDirection: 'row',alignItems:"flex-end"}}>
                <Text>
                {
                    (item.Skip)&&(item.Skip.toString() === '1'&&this.ifShowIcon('skip'))&&(<Image style={{width:10,height:18}}  source={{uri: ''}} />)
                }
                {
                    (item.Sleep)&&(item.Sleep.toString() === '1'&&this.ifShowIcon('sleep'))&&(<Image style={{width:11,height:18}}  source={{uri: ''}} />)
                }
                {
                    (item.CheckedIn)&&(item.CheckedIn.toString() === '1'&&this.ifShowIcon('checkedin'))&&(<Image style={{width:18,height:18}}  source={{uri: ''}} />)
                }
                {
                    (item.OUTHouse)&&(item.OUTHouse.toString() === '1'&&this.ifShowIcon('outhouse'))&&(<Image style={{width:18,height:18}}  source={{uri: ''}} />)
                }
                {
                    (item.ishour)&&(item.ishour.toString() ==='1'&&this.ifShowIcon('ishour'))&&(<AntDesign name={'clockcircleo'} size={15} style={{color: 'blue'}}/>)
                }
                {
                    (item.ishour)&&(item.ishour.toString() ==='2'&&this.ifShowIcon('ishour'))&&(<AntDesign name={'clockcircleo'} size={15} style={{color: 'red'}}/>)
                }
                {
                    (item.ismorning)&&(item.ismorning.toString() ==='1')&&(<Feather name={'moon'} size={15} style={{color: 'red'}}/>)
                }
                {
                    (item.Depaturs)&&(item.Depaturs.toString() === '1'&&this.ifShowIcon('depaturs'))&&(<FontAwesome name={'arrow-right'} size={15} style={{color: 'purple'}}/>)
                }
                {
                    (item.shared)&&(item.shared.toString() === '1'&&this.ifShowIcon('shared'))&&(<Image style={{width:13,height:18}}  source={{uri: ''}} />)
                }
                {
                    (item.O_Arrival)&&(item.O_Arrival.toString() === '1'&&this.ifShowIcon('o_arrival'))&&(<Image style={{width:13,height:18}}  source={{uri: ''}} />)
                }
                {
                    (item.ass)&&(item.ass !== ''&&item.ass.indexOf("选房占房")>-1&&this.ifShowIcon('ass'))&&(<FontAwesome name={'unlock'} size={15} style={{color: 'red'}}/>)
                }
                {
                    (item.ass)&&(item.ass !== ''&&item.ass.indexOf("选房占房")===-1&&this.ifShowIcon('ass'))&&(<FontAwesome name={'lock'} size={15} style={{color: '#69aa46'}}/>)
                }
                {
                    (item.V_Arrival)&&((Number(item.V_Arrival)+Number(item.O_Arrival)) >0)&&(<FontAwesome name={'arrow-left'} size={15} style={{color: '#69aa46'}}/>)
                }
                {
                    (item.F_Arrival)&&(item.F_Arrival === '1'&&this.ifShowIcon('f_arrival'))&&(<FontAwesome name={'chevron-left'} size={15} style={{color: '#69aa46'}}/>)
                }
                {
                    (item.vip)&&(item.vip!=="")&&(<FontAwesome name={'vimeo'} size={15} style={{color: 'red'}}/>)
                }
                </Text>
            </View>
        )
    };

    ifShowIcon=(item)=>{
        let ftpnoicoArr = this.state.ftpnoicoArr;
        if(ftpnoicoArr.indexOf(item)<0){
            return true;
        }else{
            return false;
        }
    }

    freshScreen=()=>{
        let {dispatch} = this.props;
        let str = {};
        dispatch(retrieveOrderSweep(JSON.stringify(str)))
    }
}


const props = state => {
    return {
        onOrderSweep:state.onOrderSweep,
    }
};

export default roomCleanScreen = connect(props)(roomCleanScreen);
